package cn.hl.hm.util.chinapay;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

/**
 * BaseServlet.java.
 */
public abstract class BaseServlet extends HttpServlet {

	/**
	 * serialVersionUID.
	 */
	private static final long serialVersionUID = -2709622388522788857L;
	/**
	 * logger.
	 */
	private Logger logger = Logger.getLogger(BaseServlet.class);

	/**
	 * doGet.
	 * @param request 请求
	 * @param response 响应
	 * @throws ServletException 异常
	 * @throws IOException 异常
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * doPost.
	 * @param request 请求
	 * @param response 响应
	 * @throws ServletException 异常
	 * @throws IOException 异常
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding(Constant.CHAR_SET);
		response.setContentType(Constant.HTML_CONTENT_TYPE);
		try {
			processAction(request, response);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			response.getWriter().write("transStat=9999&respMsg=系统繁忙");
		}
	}

	/**
	 * processAction.
	 * @param request 请求
	 * @param response 响应
	 * @throws Exception 异常
	 */
	protected abstract void processAction(HttpServletRequest request, HttpServletResponse response)
			throws Exception;

}
